import time
import threading

sum1 = 0
sum2 = 0
sum3 = 0
sum4 = 0
cmd = threading.Lock()


def figure_up_one():
    global sum1
    for i in range(50):
        prr = "txt/prr" + str(i) + ".txt"
        with open(prr, "r") as fp:
            a = fp.read()
            cmd.acquire()
            num1 = a.split('+')
            sum1 += int(num1[0]) + int(num1[1])
            cmd.release()


def figure_up_two():
    global sum2
    for i in range(50, 100):
        prr = "txt/prr" + str(i) + ".txt"
        with open(prr, "r") as fp:
            b = fp.read()
            cmd.acquire()
            num2 = b.split('+')
            sum2 += int(num2[0]) + int(num2[1])
            cmd.release()


def figure_up_three():
    global sum3
    for i in range(100, 150):
        prr = "txt/prr" + str(i) + ".txt"
        with open(prr, "r") as fp:
            c = fp.read()
            cmd.acquire()
            num3 = c.split('+')
            sum3 += int(num3[0]) + int(num3[1])
            cmd.release()


def figure_up_four():
    global sum4
    for i in range(150, 200):
        prr = "txt/prr" + str(i) + ".txt"
        with open(prr, "r") as fp:
            d = fp.read()
            cmd.acquire()
            num4 = d.split('+')
            sum4 += int(num4[0]) + int(num4[1])
            cmd.release()


def main():
    t1 = threading.Thread(target=figure_up_one)
    t2 = threading.Thread(target=figure_up_two)
    t3 = threading.Thread(target=figure_up_three)
    t4 = threading.Thread(target=figure_up_four)
    t1.start()
    time.sleep(0.5)
    t2.start()
    time.sleep(0.5)
    t3.start()
    time.sleep(0.5)
    t4.start()
    s = sum1 + sum2 +sum3 + sum4
    print(s)


if __name__ == '__main__':
    main()
